package com.dcm.user.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.user.dto.UserDto;
import com.dcm.user.entity.UserEntity;
import com.dcm.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * [用户]
 *
 * @author : [pengrongsheng]
 * @createTime : [2021/4/3]
 */
@RestController
@RequestMapping("/user")
@EnableResponseBodyAdvice
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("所有用户")
    @GetMapping("/findAll")
    public List<UserEntity> findAll() {
        return userService.findAll();
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public UserEntity login(@RequestBody UserDto userDto) {
        return userService.login(userDto);
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public void register(@RequestBody UserEntity userEntity) {
        userService.register(userEntity);
    }


}
